<template>
  <div>
    <div v-if="!isStudent" style="margin: 0 5%;">

      <el-alert
        style="margin-top: 50px;"
        title="未审核"
        :closable="false"
        type="info"
        v-if="insFormData.examineStatus==0"
        show-icon
      >
      </el-alert>

      <el-alert
        style="margin-top: 50px;"
        title="审核已通过"
        :closable="false"
        type="success"
        v-if="insFormData.examineStatus==3"
        show-icon
      >
      </el-alert>


      <el-alert
        style="margin-top: 50px;"
        title="待审核"
        :closable="false"
        type="info"
        v-if="insFormData.examineStatus==1"
        show-icon
      ></el-alert>

      <el-alert
        style="margin-top: 50px;"
        title="审核未通过，待修改中。。。"
        :closable="false"
        type="error"
        v-if="insFormData.examineStatus==2"
        show-icon
      >
      </el-alert>
    </div>

    <instructor-info :ins-form-data="insFormData"></instructor-info>
    <el-row :gutter="100">
      <el-col :span="12" :push="8" style="margin: 40px 0;" v-if="!isStudent&&insFormData.examineStatus==1">
        <el-button style="margin: 0 50px;" type="primary" @click="examineSuccess">审核通过</el-button>
        <el-button style="margin: 0 50px;" type="danger" @click="examineError">审核不通过</el-button>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import {getInstructorDetailById,changeInstructorExamineStatus} from "@/api/mentor/instructor"
  import {getInfo} from "@/api/login"
  import instructorInfo from '../../../components/InstructorInfo'
export default {
  components: {instructorInfo},
  props: [],
  data() {
    return {
      insFormData:{

      },
      insGenderOptions: [{
        "label": "男",
        "value": 1
      }, {
        "label": "女",
        "value": 0
      }],
      levelOptions: [{
        "label": "国家级",
        "value": 0
      }, {
        "label": "省级",
        "value": 1
      }, {
        "label": "厅级",
        "value": 2
      }, {
        "label": "校级",
        "value": 3
      }, {
        "label": "其他",
        "value": 4
      }],
      insId:undefined,
      roles:undefined,
      isStudent:false
    }
  },
  computed: {},
  watch: {},
  async created() {
    this.insId = this.$route.params.id
    await this.getInstructorDetail()
    await this.getUserId()
    this.isStudent = this.checkIsStudent()
  },
  mounted() {},
  methods: {
    async getInstructorDetail() {
      const res = await getInstructorDetailById(this.insId)
      // console.log(res)
      this.insFormData = res.data
    },
    async getUserId() {
      const info = await getInfo();
      this.roles = info.roles
      // console.log(info)
      this.userId = info.user.userId
      this.adminName = info.user.nickName
    },
    //审核通过
    async examineSuccess() {
      const res = await changeInstructorExamineStatus(this.adminName,3, this.insFormData.insId,"审核通过")
      // console.log(res)
      if (res.code!=200){
        this.$message.error(res.msg)
        return
      }
      await this.$router.push("/instructor/list")
    },
    //审核不通过
    async examineError() {
      const confirm = await this.$prompt('请输入未通过审核原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
      if (confirm.value==null){
        this.$message.warning("审核原因不能为空")
        return
      }
      if (confirm.action!="confirm"){
        return
      }
      const res = await changeInstructorExamineStatus(this.adminName,2, this.insFormData.insId, confirm.value)
      if (res.code!=200){
        this.$message.error(res.msg)
        return
      }
      await this.$router.push("/instructor/list")
    },
    //检查该角色是否是学生
    checkIsStudent(){
      // console.log(this.roles)
      for(let role in this.roles){
        if (role=='student'){
          return true
        }
      }
      return false
    }

  }
}

</script>
<style scoped>
.el-upload__tip {
  line-height: 1.2;
}




</style>
